;
(function(doc) {
    var Calculator = function(dom) {
        this.oCalculator = dom
        this.oFirstInput = this.oCalculator.getElementsByClassName('input')[0]
        this.oSecondInput = this.oCalculator.getElementsByClassName('input')[1]
        this.oResult = this.oCalculator.getElementsByClassName('result')[0]
        this.init()
    }
    Calculator.prototype.init = function() {
        this.bindEvent()
    }
    Calculator.prototype.bindEvent = function() {
        this.oCalculator.addEventListener('click', this.onBtnClick.bind(this), false)
    }
    Calculator.prototype.onBtnClick = function(ev) {
        console.log(ev)
        var e = ev || window.event,
            tar = e.target || e.srcElement,
            tagName = tar.tagName.toLowerCase();
        if (tagName === 'button') {
            var field = tar.getAttribute('data-field'),
                val = Number(this.oFirstInput.value) || 0,
                val2 = Number(this.oSecondInput.value) || 0;
            this.oResult.innerHTML = this.calculate(field, val, val2)
        }
    }
    Calculator.prototype.calculate = function(field, val1, val2) {
        switch (field) {
            case 'plus':
                return val1 + val2;
            case 'minus':
                return val1 - val2;
            case 'mul':
                return val1 * val2;
            case 'div':
                return val1 / val2;

        }
    }
    window.Calculator = Calculator

})(document)